import { Component } from "react";

// 引入 store
import store from "../store";

import { INCREMENT, CHANGEMSG } from "../store/actionTypes.ts";

export default class World extends Component {
  render() {
    // 获取 state
    const state = store.getState();

    return (
      <div>
        <h2>World</h2>
        <p>msg: {state.msg}</p>
        <p>count: {state.count}</p>
        <button onClick={() => store.dispatch({ type: INCREMENT })}>
          INCREMENT
        </button>
        <button onClick={() => store.dispatch({ type: CHANGEMSG })}>
          CHANGEMSG
        </button>
        <button
          onClick={() => store.dispatch({ type: CHANGEMSG, payload: "张三" })}
        >
          CHANGEMSG-张三
        </button>
        <button
          onClick={() => store.dispatch({ type: CHANGEMSG, payload: "里斯" })}
        >
          CHANGEMSG-里斯
        </button>
      </div>
    );
  }
}
